{extend name="./app/admin/view/main.html" /}
{block name="title"}用户 - {__block__}{/block}

{block name="style"}
<style>
</style>
{/block}

{block name="main"}
<header class="mipcms-container-header">
    <div class="float-left header-group">
        <h4 class="title">用户</h4> <h5 class="sub-title">{{groupcodeStr}}</h5>
    </div>
    <div class="float-right">
        <a href="{$mipInfo.domain}/{$Think.config.admin}/user/userPublish/groupcode-{$groupcode}" class="ivu-btn ivu-btn-primary ivu-btn-circle">
            <Icon type="edit"></Icon> 新建用户
        </a>
    </div>
</header>
<main class="mipcms-container-body" style="height: calc(100% - 50px)">
        <section class="mip-box">
            <section class="mip-box-body">
                <!--内容列表-->
                <section class="diy-table-list" v-cloak>
                    <div class="content-list-header clearfix">
                        <div class="float-left m-b-xs">
                            <i-input v-model="searchData" placeholder="请输入搜索的关键词" style='width: 300px;'>
                                <i-Button slot="append" icon="ios-search" @click='userSearchClick'></i-Button>
                            </i-input>
                        </div>
                        
                    </div>



                    <table class="table table-hover diy-table-list">
                        <thead>
                        <tr class="diy-table-item-header">
                            <th>头像</th>
                            <th><span>昵称</span></th>
                            <th><span>登录账号</span></th>
                            <th><span>手机号</span></th>
                            <th><span>操作</span></th>

                        </tr>
                        </thead>

                        <tbody class="diy-table-body">
                        <template v-if='userList' v-for='(u,i) in userList'>
                            <tr class="tr1 diy-table-item">
                                <td style="padding: 5px"><img :src="u.head_pic" onerror="this.src='{$mipInfo.domain}/assets/common/images/no-images.jpg'" style="height:40px"/></td>
                                <td>{{u.nickname}}</td>
                                <td>{{u.username}}</td>
                                <td>{{u.mobile}}</td>
                                <td>
                                    <Button-Group size="small" shape="circle">
                                        <i-button type="success" @click="userEdit(u)">修改</i-button>
                                        <i-button type="warning" @click="userDel(u)">删除</i-button>
                                    </Button-Group>
                                </td>

                            </tr>
                        </template>

                        <template v-if="userList.length==0">
                            <tr>
                                <td colspan="5" class="no-block">
                                    <Icon type="ios-filing-outline"></Icon>
                                    <p>暂无数据</p>
                                </td>
                            </tr>
                        </template>

                        </tbody>

                    </table>

                </section>
                <!--内容列表结束-->
                <!--分页-->
                <div class="text-right clearfix">
                    <Page :total="pagination.total"  @on-page-size-change='userPaginationSelect'
                          :page-size-opts='[10,100,500,1000,5000]' show-total show-sizer placement='top'
                          @on-change='userPaginationClick'></Page>
                </div>
            </section>
        </section>
</main>

{/block}
    
{block name="javascript"}
{__block__}
<script>
    new Vue({
        el: '#app',
        data: {
            searchData: '',
            groupcode: parseInt('{$groupcode}'),
            groupcodeStr: '',
            userList: [],
            pagination: {
                currentPage: 1,
                limit: 10,
                total: this.total,
            },
        },
        watch: { },
        mounted() {
            this.getUserList();
            this.getGroupInfo();
        },
        methods: {

            getGroupInfo:function(){
                var _this=this;
                this.$mip.ajax('{$mipInfo.domain}/user/ApiAdminUserGroup/getGroupInfo', {
                    group_code: _this.groupcode,
                }).then(function(res) {
                    _this.groupcodeStr=res.data.name;
                });
            },
            userEdit(u) {
                window.location.href = '{$mipInfo.domain}/{$Think.config.admin}/user/userPublish/uid-' + u.uid ;
            },
            //获取站点信息

            userDel(val) {
                var _this = this;
               this.$Modal.confirm({
                    title: '消息提示',
                    content: '<p>确定删除么？删除后不可恢复</p>',
                    onOk: () => {
                        _this = this;
                        this.$mip.ajax('{$mipInfo.domain}/user/ApiAdminUser/userDel', {
                            uid: val.uid,
                        }).then(function(res) {
                            if(res.code == 1) {
                                _this.$Message.success('操作成功');
                                _this.getUserList();
                            }
                        });
                    },
                    onCancel: () => {
                    }
                });
            },
            getUserList() {
                this.loading = true;
                var _this = this;
              
                this.$mip.ajax('{$mipInfo.domain}/user/ApiAdminUser/userList', {
                    status: this.status,
                    page: this.pagination.currentPage,
                    limit: this.pagination.limit,
                    keywords: this.searchData,
                    groupcode: this.groupcode,
                }).then(function(res) {
                    _this.userList = [];
                    if(res.code == 1) {
                        var userList = res.data.userList;
                        if (userList) {
                            for (var i = 0; i < userList.length; i++) {
                                userList[i].userListSelectStatus = false;
                            }
                            _this.userList = userList;
                        }
                        _this.pagination.total = res.data.total;
                    }
                    _this.loading = false;
                });
            },
            userPaginationSelect(val) {
                this.pagination.limit = val;
                this.getUserList();
            },
            userPaginationClick(val) {
                this.pagination.currentPage = val;
                this.getUserList();
            },
            //搜索
            userSearchClick: function() {
                this.getUserList();
            },
        }
    })
  </script>
{/block}